<?php
	include_once 'isLogin.php';
	
	$table_name = "keyword";
	
	//添加
	if($_GET['action']=='add'){
		$pinyinc = new str2py();
		$pinyin = $pinyinc->Pinyin($_POST['name'],1);
		
		//插入数据
		$arr = array('key'=>$_POST['name'],'pinyin'=>$pinyin);
		$commonc->insert($table_name,$arr);
		$id = $commonc->insert_id();
		
		$key = $commonc->getInfo($table_name, $id);
		
		if($id!=''){
			$return='<tr>
			<td> <input type="checkbox" name="checkbox" value="'.$id.'" /></td>
			<td name_id="'.$id.'">'.$_POST['name'].'</td>
			<td>'.$key['pinyin'].'</td>
			<td>'.$key['click'].'</td>
			<td class="xiugai">
			<a href="javascript:;" onclick="edit(\''.$id.'\',$(this),\'keyword.php?action=edit\')">修改</a>
			</td>
			</tr>';
			$arr=array('error'=>'0','content'=>$return);
		}else{
			$arr=array('error'=>'1','content'=>'添加失败');
		}
		echo json_encode($arr);
		exit();
	}
	
	//删除
	if($_GET['action']=='del'){
		echo $commonc->del($table_name,$_POST['id']);
		exit();
	}
	
	//修改
	if($_GET['action']=='edit'){
		$pinyinc = new strToPinyin();
		$pinyin = $pinyinc->Pinyin($_POST['name'],1);
		$arr = array('key'=>$_POST['name'],'pinyin'=>$pinyin);
		echo $commonc->update($table_name,$arr,"id='".$_POST['name_id']."'");
		exit();
	}
	
	//得到所有内容
	$sql = $table_name." order by id desc";
	$row=$commonc->getList($sql,$sql);
	$smarty->assign("row",$row['result']);
	$smarty->assign('page',$row['page']);
	
	$smarty->display("keyword.html");
?>